package datastruct.sort;

import java.util.Arrays;

/**
 * @program: DataStructuresAndAlgorithms
 * @description: 选择排序
 * @author: zhang
 * @create: 2020-03-12 17:27
 */
public class SelectSortDemo {

    public static void main(String[] args) {
//        int[] arr = {1, 2, 7, 3, 0, 4, 9, 2, 4, 22, 21, 20};
        int[] arr = new int[80000];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int) (Math.random() * 8000000);
        }

        long start = System.currentTimeMillis();

        for (int i = 0; i < arr.length - 1; i++) {
            int min = arr[i];
            int minIndex = i;
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[j] < min) {
                    min = arr[j];
                    minIndex = j;
                }
            }
            if (i != minIndex) {
                arr[minIndex] = arr[i];
                arr[i] = min;
            }
        }

        System.out.println(System.currentTimeMillis() - start);
        System.out.println(Arrays.toString(arr));
    }
}
